#include <amxmodx>
#include <items>
#include <engine>
#include <cstrike>
#include <fun>

new PLUGIN_NAME[] 	= "UM Item: True Armor"
new PLUGIN_AUTHOR[] 	= "Cheap_Suit"
new PLUGIN_VERSION[] 	= "1.0"

new bool:g_TrueArmor[33]
public plugin_init() 
{
	register_plugin(PLUGIN_NAME, PLUGIN_VERSION, PLUGIN_AUTHOR)
	register_item("True Armor", "Armor takes full damage", 2500)
	register_event("Damage", "Event_Damage", "be", "2!0")
}

public client_connect(id) {
	g_TrueArmor[id] = false
}

public Enable_Item(id) {
	g_TrueArmor[id] = true
}

public Disable_Item(id) {
	g_TrueArmor[id] = false
} 

public Event_Damage(id)
{
	if(!is_user_connected(id) || !is_user_alive(id)) {
		return PLUGIN_CONTINUE
	}
	
	if(!g_TrueArmor[id]) {
		return PLUGIN_CONTINUE
	}
	
	new iArmor = get_user_armor(id)
	if(iArmor > 0)
	{
		new iDamage = read_data(2)
		new iValue = (iArmor - (iDamage / 2))
		if(iValue < 0) {
			iDamage += iValue
		}
		set_user_armor(id, clamp(iValue, 0, 255))
		set_user_health(id, get_user_health(id) + iDamage)
	}
	return PLUGIN_CONTINUE
}
